# Maintainer: Pierre Schmitz <pierre@archlinux.de>

pkgbase=php-apcu
pkgname=(php-apcu php7-apcu)
pkgver=5.1.20
pkgrel=1
arch=('x86_64')
pkgdesc='A userland caching module for PHP'
url='https://pecl.php.net/package/APCu'
makedepends=('php' 'php7')
license=('PHP')
source=("https://pecl.php.net/get/apcu-$pkgver.tgz"
        'apcu.ini')
backup=('etc/php/conf.d/apcu.ini')
sha256sums=('b99d40fafec06f4d132fcee53e7526ddbfc1d041ea6e04e17389dfad28f9c390'
            '18b2d904848b185bdc7c0c6a5f7c82ec809e9ed3f137cd6d3420160f4756630f')

prepare() {
	cd "$srcdir/apcu-$pkgver"

	rm tests/apc_entry_002.phpt

	cp -a "$srcdir/apcu-$pkgver" "$srcdir/apcu7-$pkgver"
}

build() {
	cd "$srcdir/apcu-$pkgver"
	phpize
	./configure --prefix=/usr
	make

	cd "$srcdir/apcu7-$pkgver"
	phpize7
	./configure --prefix=/usr
	make
}

check() {
	export REPORT_EXIT_STATUS=1
	export NO_INTERACTION=1
	export SKIP_ONLINE_TESTS=1
	export SKIP_SLOW_TESTS=1

	for dir in "$srcdir/apcu"{,7}-$pkgver; do
		pushd "$dir"
		make test
		popd
	done
}

package_php-apcu() {
	depends=(php)

	cd "$srcdir/apcu-$pkgver"

	make INSTALL_ROOT="$pkgdir" install

	install -D -m644 "$srcdir/apcu.ini" "$pkgdir/etc/php/conf.d/apcu.ini"
	install -D -m644 apc.php "$pkgdir/usr/share/webapps/php-apcu/apc.php"
	install -D -m644 INSTALL "$pkgdir/usr/share/doc/php-apcu/install.txt"
}

package_php7-apcu() {
	depends=(php7)

	cd "$srcdir/apcu7-$pkgver"

	make INSTALL_ROOT="$pkgdir" install

	install -D -m644 "$srcdir/apcu.ini" "$pkgdir/etc/php7/conf.d/apcu.ini"
	install -D -m644 apc.php "$pkgdir/usr/share/webapps/php7-apcu/apc.php"
	install -D -m644 INSTALL "$pkgdir/usr/share/doc/php7-apcu/install.txt"
}
